import router from './router';
// 验证权限
import filterAsyncRouter from "./utils/verifyPermission";

function handleRouter (roesList) {
    let permissionRoutes = filterAsyncRouter(roesList);
    let temp = router.options.routes;
    console.log([...temp,...permissionRoutes]);
    router.options.routes = [...temp,...permissionRoutes];
    router.addRoutes(permissionRoutes);
    //resetRouter();
}
//使用钩子函数对路由进行权限跳转
router.beforeEach((to, from, next) => {
    document.title = `${to.meta.title} | vue-manage-system`;
    handleRouter();
    // 刷新路由
    if (to.matched.length >  0) {
        next()
    }else{
        next(to.path)
    }
    // if (to.path == "/dashboard") {
    //     next()
    // }else{
    //     next("/dashboard");
    // }
});